package CtrlLayer;
import java.util.ArrayList;
import ModelLayer.*;

public class ProductController
{

    private ProductContainer productContainer;

    public ProductController()
    {
        productContainer = ProductContainer.getInstance();
        //createProductObjects();
    }

    //     public void createProductObjects(){  
    //         productContainer.addProduct(new Product(100001,"Sink", 1000, 0, 10, 1,2, "Bathroom"));
    //         productContainer.addProduct(new Product(200002,"Cupboard",  1200, 0, 11,1,2, "Kitchen"));
    //         productContainer.addProduct(new Product(300003,"Sofa",  2000, 0, 12,1,2, "Other"));
    //     }

    public boolean createProduct(int barcode, String name,  double sellingPrice, double leasingPrice, 
    double priceForDiscount, int amountForDiscount, int amount, int minAmount, int maxAmount, 
    int contractorId, int category){
        boolean added = false;
        if(findProduct(barcode) == null) {
            productContainer.addProduct(new Product(barcode, name, sellingPrice, leasingPrice, priceForDiscount, 
            amountForDiscount, amount, minAmount, maxAmount, contractorId, category));
            added = true;
        } else {
            added = false;
        }
        return added;
    }

    public Product findProduct(int barcode){    
        return  productContainer.findProductByBarcode(barcode);
    }

    public void deleteProduct(int barcode){
        productContainer.deleteProduct(productContainer.findProductByBarcode(barcode));
    }

    public void updateProduct(int barcode, String name,  double sellingPrice, double leasingPrice, 
    double priceForDiscount, int amountForDiscount, int amount,
    int minAmount, int maxAmount, int contractorId, int category){
        Product p =  productContainer.findProductByBarcode(barcode);
        if(p != null){
            p.setName(name);
            p.setSellingPrice(sellingPrice);
            p.setLeasingPrice(leasingPrice);
            p.setPriceForDiscount(priceForDiscount);
            p.setAmountForDiscount(amountForDiscount);
            p.setAmount(amount);
            p.setMinAmount(minAmount);
            p.setMaxAmount(maxAmount);
            p.setContractorId(contractorId);
            p.setLocationCode(category);
        }
    }
}
